package club.banyuan.oop.RentalDemo;

import java.util.Scanner;

/**
 * @author edz
 * @version 1.0
 * @date 2020/11/18 下午3:33
 */
public class Garage {
    private int carport;

    public int getCarport() {
        return carport;
    }

    public void setCarport(int carport) {
        this.carport = carport;
    }

    int count=-1;
//    Garage[] garages = new Garage[5];
    Car[] cars = new Car[5];
    Car car = new Car();


//    {
//        for (int i = 0; i < cars.length; i++) {
//            car.setCarId("2323" + i);
//            car.setCarBrand("别克");
//            cars[i] = car;
//        }
//    }

    public void addCar(Car car) {
        for (int i = 0; i < cars.length; i++) {
            if (cars[i] == null) {
                Scanner scanner = new Scanner(System.in);
                System.out.println("请输入车牌号");
                String carId = scanner.next();
                System.out.println("请输入车品牌");
                String carBrand = scanner.next();
                car.setCarId(carId);
                car.setCarBrand(carBrand);
                count++;
                cars[i] = car;
                System.out.println("入库成功");
                break;
            } else {
                System.out.println("车库已满");
            }
        }
    }


    public Car removeCar(String carId) {
        Scanner scanner = new Scanner(System.in );
        System.out.println("请输入要出库的车辆牌照");
        String carId1=scanner.next();
        for (int i = 0; i < cars.length; i++) {
            if (cars[i].getCarId().equals(carId1)) {
                cars[i]=null;
            }
        }
        return null;
    }

    public void showInfoAll() {
        for (int i = 0; i < cars.length; i++) {
            System.out.println(car);
        }
    }

    public Car[] getByCarBrand(String brand){
        for (int i = 0; i <cars.length ; i++) {
            if(cars[i].getCarBrand().equals(brand)){
                System.out.println(cars[i]);
            }
        }
        return cars;
    }


}
